package com.example.demo.controller;


import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/login")
@RestController
public class LoginController {
    @RequestMapping("/check")
    public boolean check(String username, String password, HttpSession session) {
        System.out.println("username:"+username+" password:"+password);
        if(!StringUtils.hasLength(username) && !StringUtils.hasLength(password)) {
            return false;
        }

        if("zhangsan".equals(username) && "123456".equals(password)) {
//            并获取会话
            session.setAttribute("username", "zhangsan");
            return true;
        }
        return false;
    }

    @RequestMapping("/index")
    public String index(HttpSession session) {
        return (String) session.getAttribute("username");
    }
}
